<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @author Thanh Nguyen Dinh<thanhnguyendinh@admicro.vn>
 * @copyright 2013
 */
class Contact extends MX_Controller
{
    
    public function __construct()
    {
        parent::__construct();
        $this->load->library('Default_Layout');
        $this->load->library('Minifier');
        $this->load->model('contact/contact_model');
    }

    public function index()    
    {    
        $data =array(); 
        $data['errors'] ='';       
        $data['ok'] = 0;        
        $this->minifier->AddJsNoPack('jquery.validate');
        $this->default_layout->_loadHeader('');
        $input = $this->input->post();
    	if($input['name'] && $input['website'] && $input['email'] && $input['phone'] && strlen($input['name']) > 10 && strlen($input['phone']) > 5){    		
            unset($input['Submit']);
            $data_contact = array('name'=>$input['name'],
            						'website'=>$input['website'],
            						'email'=>$input['email'],
            						'phone'=>$input['phone'],
            						'type'=>1,
            						'status'=>1	
            					);
            $return  = $this->contact_model->insert_contact($data_contact);
            if($return)
            	$data['ok'] = 1;
            else            
            	$data['errors'] = "Gửi không thành công!";
        }
        $data['frmToken'] = uniqid();
        $this->session->set_userdata('frmToken',$data['frmToken']);
        $this->load->view('contact/contact_view',$data);     
        $this->default_layout->_loadFooter();  
        
    }
    
  
    
     

}

?>
